from tkinter import *

# 创建主窗口
root = Tk()
root.title("Pack布局管理器示例")

# 创建Frame容器用于演示不同的pack属性
frame1 = Frame(root, bg='lightgray', padx=10, pady=10)
frame1.pack()

# 1. expand属性示例 - 设置组件填充方式
label1 = Label(frame1, text="expand=True示例", bg='yellow')
label1.pack(expand=True, fill='both', pady=5)

# 2. fill属性示例 - 设置填充额外空间
label2 = Label(frame1, text="fill='x'示例", bg='lightgreen')
label2.pack(fill='x', pady=5)

label3 = Label(frame1, text="fill='y'示例", bg='lightblue')
label3.pack(fill='y', pady=5)

label4 = Label(frame1, text="fill='both'示例", bg='pink')
label4.pack(fill='both', pady=5)

# 3. side属性示例 - 设置组件的分布方式
frame2 = Frame(root, bg='lightgray', padx=10, pady=10)
frame2.pack(pady=10)

Label(frame2, text="TOP", bg='cyan').pack(side='top')
Label(frame2, text="BOTTOM", bg='cyan').pack(side='bottom')
Label(frame2, text="LEFT", bg='cyan').pack(side='left')
Label(frame2, text="RIGHT", bg='cyan').pack(side='right')

button_one = Button(text='按钮1')
button_one.pack(side=LEFT)
button_two = Button(text='按钮2')
button_two.pack(side=RIGHT)
button_three = Button(text='按钮3')
button_three.pack(side=TOP)
button_four = Button(text='按钮4')
button_four.pack(side=BOTTOM)

# 启动主循环
root.mainloop()